<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="高德地图的使用, 潘腾龙">
    <meta name="description" content="关于高德地图的使用最近在做一款iOS APP，用到了地图功能，出于多方考虑，使用了高德地图，来实现，实时轨迹、轨迹循迹、在地图上显示自定义大头针，轨迹平滑处理、加载高德地图瓦片功能等，在这里做一下总结。
地图初始化
首先，根据高德开发文档，">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    

    <title>高德地图的使用 | 潘腾龙</title>
    <link rel="icon" type="image/png" href="/PTLBlog/favicon.png">

    <link rel="stylesheet" type="text/css" href="/PTLBlog/libs/awesome/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/PTLBlog/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/PTLBlog/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/PTLBlog/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/PTLBlog/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/PTLBlog/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/PTLBlog/css/my.css">

    <script src="/PTLBlog/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/PTLBlog/atom.xml" title="潘腾龙" type="application/atom+xml">
<link rel="stylesheet" href="/PTLBlog/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/PTLBlog/" class="waves-effect waves-light">
                    
                    <img src="/PTLBlog/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">潘腾龙</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/PTLBlog/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/PTLBlog/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/PTLBlog/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/PTLBlog/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/PTLBlog/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/PTLBlog/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/PTLBlog/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/PTLBlog/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">潘腾龙</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/PTLBlog/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/PTLBlog/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/PTLBlog/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/PTLBlog/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/PTLBlog/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/PTLBlog/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/PTLBlog/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://jackptl.gitee.io/ptlblog/" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>联系我
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://jackptl.gitee.io/ptlblog/" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="联系我" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/PTLBlog/medias/featureimages/16.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">高德地图的使用</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/PTLBlog/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/PTLBlog/tags/iOS%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/">
                                <span class="chip bg-color">iOS基础知识总结</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/PTLBlog/categories/iOS%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/" class="post-category">
                                iOS基础知识总结
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-01-07
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2022-07-25
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    2.3k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    11 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h4 id="关于高德地图的使用"><a href="#关于高德地图的使用" class="headerlink" title="关于高德地图的使用"></a>关于高德地图的使用</h4><p>最近在做一款iOS APP，用到了地图功能，出于多方考虑，使用了高德地图，来实现，实时轨迹、轨迹循迹、在地图上显示自定义大头针，轨迹平滑处理、加载高德地图瓦片功能等，在这里做一下总结。</p>
<h5 id="地图初始化"><a href="#地图初始化" class="headerlink" title="地图初始化"></a>地图初始化</h5><ol>
<li>首先，根据高德开发文档，将SDK导入到项目中，这里不做赘述</li>
<li>导入成功后，在.h文件中引入头文件：<ul>
<li>import AMapFoundationKit&#x2F;AMapFoundationKit.h</li>
<li>import MAMapKit&#x2F;MAMapKit.h</li>
<li>import AMapLocationKit&#x2F;AMapLocationManager.h</li>
</ul>
</li>
<li>初始化地图：<br> 设置属性</li>
</ol>
<pre class=" language-objectivec"><code class="language-objectivec"> <span class="token comment" spellcheck="true">// 高德地图</span>
<span class="token keyword">@property</span> <span class="token punctuation">(</span>nonatomic<span class="token punctuation">,</span> strong<span class="token punctuation">)</span> MAMapView <span class="token operator">*</span>mapView<span class="token punctuation">;</span>
 <span class="token comment" spellcheck="true">// 定位管理者</span>
<span class="token keyword">@property</span> <span class="token punctuation">(</span>nonatomic<span class="token punctuation">,</span> strong<span class="token punctuation">)</span> AMapLocationManager <span class="token operator">*</span>locationManager<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// 地图瓦片</span>
<span class="token keyword">@property</span> <span class="token punctuation">(</span>nonatomic<span class="token punctuation">,</span> strong<span class="token punctuation">)</span> MATileOverlay <span class="token operator">*</span>tileOverlay
</code></pre>
<p>  懒加载地图   </p>
<pre class=" language-objectivec"><code class="language-objectivec"> pragma mark <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>懒加载
<span class="token comment" spellcheck="true">// 定位管理者</span>
<span class="token operator">-</span> <span class="token punctuation">(</span>AMapLocationManager <span class="token operator">*</span><span class="token punctuation">)</span>locationManager <span class="token punctuation">{</span>
  
  <span class="token keyword">if</span> <span class="token punctuation">(</span>_locationManager <span class="token operator">==</span> nil<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      AMapLocationManager <span class="token operator">*</span>locationManager <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>AMapLocationManager alloc<span class="token punctuation">]</span> init<span class="token punctuation">]</span><span class="token punctuation">;</span>
      locationManager<span class="token punctuation">.</span>delegate <span class="token operator">=</span> <span class="token keyword">self</span><span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 定位的最小更新距离</span>
      locationManager<span class="token punctuation">.</span>distanceFilter <span class="token operator">=</span> <span class="token number">50</span><span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 指定定位是否会被系统自动暂停。默认为NO。</span>
      locationManager<span class="token punctuation">.</span>pausesLocationUpdatesAutomatically <span class="token operator">=</span> NO<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 是否允许后台定位。默认为NO。</span>
      locationManager<span class="token punctuation">.</span>allowsBackgroundLocationUpdates <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 连续定位是否返回逆地理信息，默认NO。</span>
      locationManager<span class="token punctuation">.</span>locatingWithReGeocode <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      locationManager<span class="token punctuation">.</span>desiredAccuracy <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
      _locationManager <span class="token operator">=</span> locationManager<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  
  <span class="token keyword">return</span> _locationManager<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">// MapView</span>
<span class="token operator">-</span><span class="token punctuation">(</span>MAMapView <span class="token operator">*</span><span class="token punctuation">)</span>mapView<span class="token punctuation">{</span>
  
  <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>_mapView<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment" spellcheck="true">// 1、地图</span>
      MAMapView <span class="token operator">*</span>mapView <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MAMapView alloc<span class="token punctuation">]</span> initWithFrame<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>view<span class="token punctuation">.</span>bounds<span class="token punctuation">]</span><span class="token punctuation">;</span>
      mapView<span class="token punctuation">.</span>delegate <span class="token operator">=</span> <span class="token keyword">self</span><span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 是否显示用户位置（定位蓝点）</span>
      mapView<span class="token punctuation">.</span>showsUserLocation <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      mapView<span class="token punctuation">.</span>userTrackingMode <span class="token operator">=</span> MAUserTrackingModeFollow<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 是否显示室内地图, 默认NO</span>
      mapView<span class="token punctuation">.</span>showsIndoorMap <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 地图类型</span>
      mapView<span class="token punctuation">.</span>mapType <span class="token operator">=</span> MAMapTypeStandard<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 地图logo（高德地图字样）</span>
      <span class="token comment" spellcheck="true">//    mapView.logoCenter</span>
      <span class="token comment" spellcheck="true">// 指南针</span>
      mapView<span class="token punctuation">.</span>showsCompass <span class="token operator">=</span> NO<span class="token punctuation">;</span>
      mapView<span class="token punctuation">.</span>compassOrigin <span class="token operator">=</span> <span class="token function">CGPointMake</span><span class="token punctuation">(</span>kScreenWidth<span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 比例尺</span>
      mapView<span class="token punctuation">.</span>showsScale<span class="token operator">=</span> YES<span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//设置成NO表示不显示比例尺；YES表示显示比例尺</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>kIsIphoneX<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          mapView<span class="token punctuation">.</span>scaleOrigin<span class="token operator">=</span> <span class="token function">CGPointMake</span><span class="token punctuation">(</span>_mapView<span class="token punctuation">.</span>scaleOrigin<span class="token punctuation">.</span>x<span class="token punctuation">,</span>kScreenHeight<span class="token number">-300</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//设置比例尺位置</span>
      <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
          mapView<span class="token punctuation">.</span>scaleOrigin<span class="token operator">=</span> <span class="token function">CGPointMake</span><span class="token punctuation">(</span>_mapView<span class="token punctuation">.</span>scaleOrigin<span class="token punctuation">.</span>x<span class="token punctuation">,</span>kScreenHeight<span class="token number">-53</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment" spellcheck="true">//设置比例尺位置</span>
      <span class="token punctuation">}</span>
      <span class="token comment" spellcheck="true">// 是否支持缩放, 默认YES</span>
      mapView<span class="token punctuation">.</span>zoomEnabled <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 缩放级别（默认3-19，有室内地图时为3-20）</span>
      mapView<span class="token punctuation">.</span>zoomLevel <span class="token operator">=</span> <span class="token number">17</span><span class="token punctuation">;</span>
      mapView<span class="token punctuation">.</span>minZoomLevel <span class="token operator">=</span> kTileOverlayRemoteMinZoom<span class="token punctuation">;</span>
      mapView<span class="token punctuation">.</span>maxZoomLevel <span class="token operator">=</span> kTileOverlayRemoteMaxZoom<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 是否支持平移, 默认YES</span>
      mapView<span class="token punctuation">.</span>scrollEnabled <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 是否支持旋转, 默认YES</span>
      mapView<span class="token punctuation">.</span>rotateEnabled <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">// 是否支持倾斜, 默认YES（用户可以在地图上放置两个手指，移动它们一起向下或向上去增加或减小倾斜角。）</span>
      mapView<span class="token punctuation">.</span>rotateCameraEnabled <span class="token operator">=</span> YES<span class="token punctuation">;</span>
      _mapView <span class="token operator">=</span> mapView<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  _mapView<span class="token punctuation">.</span>delegate <span class="token operator">=</span> <span class="token keyword">self</span><span class="token punctuation">;</span>
  <span class="token keyword">return</span> _mapView<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>   然后将将地图添加到View上</p>
<pre class=" language-objectivec"><code class="language-objectivec"> <span class="token comment" spellcheck="true">// 高德地图</span>
 <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>view addSubview<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView<span class="token punctuation">]</span><span class="token punctuation">;</span>
 <span class="token comment" spellcheck="true">// 开启持续定位</span>
 <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>locationManager startUpdatingLocation<span class="token punctuation">]</span><span class="token punctuation">;</span>
</code></pre>
<p>  这里因为要实时绘制行走的路线轨迹，所以使用持续定位，到这里，地图已经显示出来了</p>
<h5 id="使用高德地图加载谷歌地图瓦片（地形图和卫星图）"><a href="#使用高德地图加载谷歌地图瓦片（地形图和卫星图）" class="headerlink" title="使用高德地图加载谷歌地图瓦片（地形图和卫星图）"></a>使用高德地图加载谷歌地图瓦片（地形图和卫星图）</h5><p>设置默认  地图</p>
<pre class=" language-objectivec"><code class="language-objectivec"><span class="token comment" spellcheck="true">// Google地形瓦片地图URL</span>
define kTileOverlayGoogleTopography <span class="token string">@"http://mt2.google.cn/vt/lyrs=p&amp;scale=2&amp;hl=zh-CN&amp;gl=cn&amp;x={x}&amp;y={y}&amp;z={z}"</span>

<span class="token comment" spellcheck="true">// Google卫星瓦片地图URL</span>
define kTileOverlayGoogleSatellite <span class="token string">@"http://mt2.google.cn/vt/lyrs=y&amp;scale=2&amp;hl=zh-CN&amp;gl=cn&amp;x={x}&amp;y={y}&amp;z={z}"</span>

<span class="token comment" spellcheck="true">// 瓦片最小缩放级别</span>
define kTileOverlayRemoteMinZoom <span class="token number">3</span>

<span class="token comment" spellcheck="true">// 瓦片最大缩放级别</span>
define kTileOverlayRemoteMaxZoom <span class="token number">19</span>


pragma mark <span class="token operator">-</span> 构建Google瓦片
<span class="token operator">-</span> <span class="token punctuation">(</span>MATileOverlay <span class="token operator">*</span><span class="token punctuation">)</span>constructGoogleTileOverlay<span class="token punctuation">:</span><span class="token punctuation">(</span>NSString <span class="token operator">*</span><span class="token punctuation">)</span>url <span class="token punctuation">{</span>
    MATileOverlay <span class="token operator">*</span>tileOverlay <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MATileOverlay alloc<span class="token punctuation">]</span> initWithURLTemplate<span class="token punctuation">:</span>url<span class="token punctuation">]</span><span class="token punctuation">;</span>
    tileOverlay<span class="token punctuation">.</span>minimumZ <span class="token operator">=</span> kTileOverlayRemoteMinZoom<span class="token punctuation">;</span>
    tileOverlay<span class="token punctuation">.</span>maximumZ <span class="token operator">=</span> kTileOverlayRemoteMaxZoom<span class="token punctuation">;</span>
    tileOverlay<span class="token punctuation">.</span>boundingMapRect <span class="token operator">=</span> MAMapRectWorld<span class="token punctuation">;</span>
    
    <span class="token keyword">return</span> tileOverlay<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">/**
 * @brief 根据overlay生成对应的Renderer
 * @param mapView 地图View
 * @param overlay 指定的overlay
 * @return 生成的覆盖物Renderer
 */</span>
<span class="token operator">-</span> <span class="token punctuation">(</span>MAOverlayRenderer <span class="token operator">*</span><span class="token punctuation">)</span>mapView<span class="token punctuation">:</span><span class="token punctuation">(</span>MAMapView <span class="token operator">*</span><span class="token punctuation">)</span>mapView rendererForOverlay<span class="token punctuation">:</span><span class="token punctuation">(</span>id<span class="token operator">&lt;</span>MAOverlay<span class="token operator">></span><span class="token punctuation">)</span>overlay <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">[</span>overlay isKindOfClass<span class="token punctuation">:</span><span class="token punctuation">[</span>MATileOverlay class<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment" spellcheck="true">// 瓦片</span>
        MATileOverlayRenderer <span class="token operator">*</span>render <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MATileOverlayRenderer alloc<span class="token punctuation">]</span> initWithTileOverlay<span class="token punctuation">:</span>overlay<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> render<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> nil<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token operator">-</span> <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>setMapStyp<span class="token punctuation">{</span>
    NSInteger mapType <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>NSUserDefaults standardUserDefaults<span class="token punctuation">]</span> integerForKey<span class="token punctuation">:</span><span class="token string">@"mapType"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>mapType <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView removeOverlays<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView<span class="token punctuation">.</span>overlays<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>mapType <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment" spellcheck="true">// 移除所有瓦片</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView removeOverlays<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView<span class="token punctuation">.</span>overlays<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">// 构建Google地形瓦片</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView addOverlay<span class="token punctuation">:</span><span class="token punctuation">[</span><span class="token keyword">self</span> constructGoogleTileOverlay<span class="token punctuation">:</span>kTileOverlayGoogleTopography<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>mapType <span class="token operator">==</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView removeOverlays<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView<span class="token punctuation">.</span>overlays<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">// 构建Google卫星瓦片</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView addOverlay<span class="token punctuation">:</span><span class="token punctuation">[</span><span class="token keyword">self</span> constructGoogleTileOverlay<span class="token punctuation">:</span>kTileOverlayGoogleSatellite<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h5 id="实时轨迹画线"><a href="#实时轨迹画线" class="headerlink" title="实时轨迹画线"></a>实时轨迹画线</h5><p>首先在地图的代理中，采集画轨迹所需要的坐标点</p>
<pre class=" language-objectivec"><code class="language-objectivec">pragma mark <span class="token operator">-</span> 位置更新之后

<span class="token operator">-</span> <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>amapLocationManager<span class="token punctuation">:</span><span class="token punctuation">(</span>AMapLocationManager <span class="token operator">*</span><span class="token punctuation">)</span>manager didUpdateLocation<span class="token punctuation">:</span><span class="token punctuation">(</span>CLLocation <span class="token operator">*</span><span class="token punctuation">)</span>location reGeocode<span class="token punctuation">:</span><span class="token punctuation">(</span>AMapLocationReGeocode <span class="token operator">*</span><span class="token punctuation">)</span>reGeocode <span class="token punctuation">{</span>
    
    
    <span class="token comment" spellcheck="true">// 底部显示坐标</span>
    <span class="token keyword">self</span><span class="token punctuation">.</span>locationLabel<span class="token punctuation">.</span>text <span class="token operator">=</span> <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%lf %lf"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>longitude<span class="token punctuation">,</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>latitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">// 底部显示的海拔</span>
    <span class="token keyword">self</span><span class="token punctuation">.</span>altitudeLabel<span class="token punctuation">.</span>text <span class="token operator">=</span> <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%.fM"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>altitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
    
    
    <span class="token comment" spellcheck="true">// 如果点了暂停，不在往数组里添加点</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>isPause<span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>
    
    <span class="token comment" spellcheck="true">// 如果还在初始化中，不在往数组里添加点</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>showSetUpView<span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>
    
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>locationMutableArray<span class="token punctuation">.</span>count<span class="token operator">></span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        
        <span class="token comment" spellcheck="true">// 从位置数组中取出最后一个点的位置</span>
        NSMutableDictionary <span class="token operator">*</span>getPointDict <span class="token operator">=</span> <span class="token keyword">self</span><span class="token punctuation">.</span>locationMutableArray<span class="token punctuation">.</span>lastObject<span class="token punctuation">;</span>
        
        <span class="token comment" spellcheck="true">// 计算当前位置和上一个点之间的时间间隔</span>
        NSString <span class="token operator">*</span>fromDateStr <span class="token operator">=</span> getPointDict<span class="token punctuation">[</span><span class="token string">@"time"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        NSString <span class="token operator">*</span>toDateStr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>dateFormatter stringFromDate<span class="token punctuation">:</span>location<span class="token punctuation">.</span>timestamp<span class="token punctuation">]</span><span class="token punctuation">;</span>
        NSInteger secondsInterval <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span> caculateDateWithFromDateStr<span class="token punctuation">:</span>fromDateStr toDateStr<span class="token punctuation">:</span>toDateStr<span class="token punctuation">]</span><span class="token punctuation">;</span>
        
        <span class="token comment" spellcheck="true">// 如果时间间隔小于2秒，不记录</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>secondsInterval<span class="token operator">&lt;</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>
        
        <span class="token comment" spellcheck="true">// 计算当前位置和上一个点之间的距离</span>
        NSString <span class="token operator">*</span>latitudeStr <span class="token operator">=</span> getPointDict<span class="token punctuation">[</span><span class="token string">@"latitude"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        NSString <span class="token operator">*</span>longitudeStr <span class="token operator">=</span> getPointDict<span class="token punctuation">[</span><span class="token string">@"longitude"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        
        <span class="token comment" spellcheck="true">// 拿到当前位置数据</span>
        CLLocationCoordinate2D endCoordinate<span class="token punctuation">;</span>
        endCoordinate<span class="token punctuation">.</span>latitude <span class="token operator">=</span> location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>latitude<span class="token punctuation">;</span>
        endCoordinate<span class="token punctuation">.</span>longitude <span class="token operator">=</span> location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>longitude<span class="token punctuation">;</span>

        <span class="token keyword">double</span> meters <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span> distanceBetweenOrderBy<span class="token punctuation">:</span>latitudeStr<span class="token punctuation">.</span>doubleValue <span class="token punctuation">:</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>latitude <span class="token punctuation">:</span>longitudeStr<span class="token punctuation">.</span>doubleValue <span class="token punctuation">:</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>longitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        
        <span class="token comment" spellcheck="true">// 大于所少米可以记录</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>travalType <span class="token operator">!=</span> <span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>meters<span class="token operator">&lt;</span><span class="token keyword">self</span><span class="token punctuation">.</span>travalTypeM<span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment" spellcheck="true">// 速度大于200公里/时</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>meters<span class="token operator">/</span>secondsInterval<span class="token punctuation">)</span><span class="token operator">></span><span class="token number">55.555</span><span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">// 计算行走的米数</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span> caculateTrackDistanceWithUserLocation<span class="token punctuation">:</span>location<span class="token punctuation">]</span><span class="token punctuation">;</span>
        
        <span class="token comment" spellcheck="true">// 将点数据添加到数组中</span>
        NSString <span class="token operator">*</span>pointDate <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>dateFormatter stringFromDate<span class="token punctuation">:</span>location<span class="token punctuation">.</span>timestamp<span class="token punctuation">]</span><span class="token punctuation">;</span>
        NSMutableDictionary <span class="token operator">*</span>pointDict <span class="token operator">=</span> <span class="token punctuation">[</span>NSMutableDictionary dictionary<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"longitude"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%f"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>longitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"latitude"</span><span class="token punctuation">]</span>  <span class="token operator">=</span> <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%f"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>latitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"altitude"</span><span class="token punctuation">]</span> <span class="token operator">=</span>  <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%.f"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>altitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"time"</span><span class="token punctuation">]</span> <span class="token operator">=</span> pointDate<span class="token punctuation">;</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>locationMutableArray addObject<span class="token punctuation">:</span>pointDict<span class="token punctuation">]</span><span class="token punctuation">;</span>
        
        NSString <span class="token operator">*</span>altitude <span class="token operator">=</span> <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%.f"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>altitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>altitudeArray addObject<span class="token punctuation">:</span>altitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        
        <span class="token comment" spellcheck="true">// 画线</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span> drawLine<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>

        <span class="token comment" spellcheck="true">// 将点数据添加到数组中</span>
        NSString <span class="token operator">*</span>pointDate <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>dateFormatter stringFromDate<span class="token punctuation">:</span>location<span class="token punctuation">.</span>timestamp<span class="token punctuation">]</span><span class="token punctuation">;</span>
        NSMutableDictionary <span class="token operator">*</span>pointDict <span class="token operator">=</span> <span class="token punctuation">[</span>NSMutableDictionary dictionary<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"longitude"</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%f"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>longitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"latitude"</span><span class="token punctuation">]</span>  <span class="token operator">=</span> <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%f"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>coordinate<span class="token punctuation">.</span>latitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"altitude"</span><span class="token punctuation">]</span> <span class="token operator">=</span>  <span class="token punctuation">[</span>NSString stringWithFormat<span class="token punctuation">:</span><span class="token string">@"%.f"</span><span class="token punctuation">,</span>location<span class="token punctuation">.</span>altitude<span class="token punctuation">]</span><span class="token punctuation">;</span>
        pointDict<span class="token punctuation">[</span><span class="token string">@"time"</span><span class="token punctuation">]</span> <span class="token operator">=</span> pointDate<span class="token punctuation">;</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>locationMutableArray addObject<span class="token punctuation">:</span>pointDict<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">// 添加起点坐标View</span>
        <span class="token keyword">self</span><span class="token punctuation">.</span>startAnnotation<span class="token punctuation">.</span>coordinate <span class="token operator">=</span> location<span class="token punctuation">.</span>coordinate<span class="token punctuation">;</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView addAnnotation<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>startAnnotation<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">/// 画线</span>
<span class="token operator">-</span> <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>drawLine<span class="token punctuation">{</span>
    
    <span class="token comment" spellcheck="true">// 先移除</span>
    <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView removeOverlay<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>smoothedTrace<span class="token punctuation">]</span><span class="token punctuation">;</span>
    
    MASmoothPathTool <span class="token operator">*</span>tool <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MASmoothPathTool alloc<span class="token punctuation">]</span> init<span class="token punctuation">]</span><span class="token punctuation">;</span>
    tool<span class="token punctuation">.</span>intensity <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">;</span>
    tool<span class="token punctuation">.</span>threshHold <span class="token operator">=</span> <span class="token number">0.25</span><span class="token punctuation">;</span>
    tool<span class="token punctuation">.</span>noiseThreshhold <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
    
    NSMutableArray <span class="token operator">*</span>tempArray <span class="token operator">=</span> <span class="token punctuation">[</span>NSMutableArray array<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">/// 将自己的点Model转换成MALonLatPoint</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span>NSMutableDictionary <span class="token operator">*</span>pointDict <span class="token keyword">in</span> <span class="token keyword">self</span><span class="token punctuation">.</span>locationMutableArray<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        MALonLatPoint <span class="token operator">*</span>smoothPoint <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MALonLatPoint alloc<span class="token punctuation">]</span>init<span class="token punctuation">]</span><span class="token punctuation">;</span>
        smoothPoint<span class="token punctuation">.</span>lat <span class="token operator">=</span> <span class="token punctuation">[</span>pointDict<span class="token punctuation">[</span><span class="token string">@"latitude"</span><span class="token punctuation">]</span> floatValue<span class="token punctuation">]</span><span class="token punctuation">;</span>
        smoothPoint<span class="token punctuation">.</span>lon <span class="token operator">=</span> <span class="token punctuation">[</span>pointDict<span class="token punctuation">[</span><span class="token string">@"longitude"</span><span class="token punctuation">]</span> floatValue<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">[</span>tempArray addObject<span class="token punctuation">:</span>smoothPoint<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token comment" spellcheck="true">// 平滑处理之后的坐标点</span>
    NSArray <span class="token operator">*</span>smoothedTraceArray <span class="token operator">=</span> <span class="token punctuation">[</span>tool pathOptimize<span class="token punctuation">:</span>tempArray<span class="token punctuation">]</span><span class="token punctuation">;</span>
    CLLocationCoordinate2D <span class="token operator">*</span>pCoords <span class="token operator">=</span> <span class="token function">malloc</span><span class="token punctuation">(</span><span class="token keyword">sizeof</span><span class="token punctuation">(</span>CLLocationCoordinate2D<span class="token punctuation">)</span> <span class="token operator">*</span> smoothedTraceArray<span class="token punctuation">.</span>count<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>pCoords<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> smoothedTraceArray<span class="token punctuation">.</span>count<span class="token punctuation">;</span> <span class="token operator">++</span>i<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        MALonLatPoint <span class="token operator">*</span>p <span class="token operator">=</span> <span class="token punctuation">[</span>smoothedTraceArray objectAtIndex<span class="token punctuation">:</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
        CLLocationCoordinate2D <span class="token operator">*</span>pCur <span class="token operator">=</span> pCoords <span class="token operator">+</span> i<span class="token punctuation">;</span>
        pCur<span class="token operator">-></span>latitude <span class="token operator">=</span> p<span class="token punctuation">.</span>lat<span class="token punctuation">;</span>
        pCur<span class="token operator">-></span>longitude <span class="token operator">=</span> p<span class="token punctuation">.</span>lon<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">self</span><span class="token punctuation">.</span>smoothedTrace <span class="token operator">=</span> <span class="token punctuation">[</span>MAPolyline polylineWithCoordinates<span class="token punctuation">:</span>pCoords count<span class="token punctuation">:</span>tempArray<span class="token punctuation">.</span>count<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView addOverlay<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>smoothedTrace<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>pCoords<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">free</span><span class="token punctuation">(</span>pCoords<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">// 计算两个日期的差值</span>
<span class="token operator">-</span> <span class="token punctuation">(</span>NSInteger<span class="token punctuation">)</span>caculateDateWithFromDateStr<span class="token punctuation">:</span><span class="token punctuation">(</span>NSString<span class="token operator">*</span><span class="token punctuation">)</span>fromDateStr toDateStr<span class="token punctuation">:</span><span class="token punctuation">(</span>NSString<span class="token operator">*</span><span class="token punctuation">)</span>toDateStr<span class="token punctuation">{</span>
    
    NSDate <span class="token operator">*</span>fromDate <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>dateFormatter dateFromString<span class="token punctuation">:</span>fromDateStr<span class="token punctuation">]</span><span class="token punctuation">;</span>
    NSDate <span class="token operator">*</span>toDate <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>dateFormatter dateFromString<span class="token punctuation">:</span>toDateStr<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">// 创建日历类</span>
    NSCalendar <span class="token operator">*</span>calendar <span class="token operator">=</span> <span class="token punctuation">[</span>NSCalendar currentCalendar<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">// 设置比较的级别：秒</span>
    NSCalendarUnit unit <span class="token operator">=</span> NSCalendarUnitSecond<span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">//比较的结果是NSDateComponents类对象</span>
    NSDateComponents <span class="token operator">*</span>delta <span class="token operator">=</span> <span class="token punctuation">[</span>calendar components<span class="token punctuation">:</span>unit fromDate<span class="token punctuation">:</span>fromDate toDate<span class="token punctuation">:</span>toDate options<span class="token punctuation">:</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> delta<span class="token punctuation">.</span>second<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">/// 计算两个经纬度之间的距离</span>
<span class="token operator">-</span><span class="token punctuation">(</span><span class="token keyword">double</span><span class="token punctuation">)</span>distanceBetweenOrderBy<span class="token punctuation">:</span><span class="token punctuation">(</span><span class="token keyword">double</span><span class="token punctuation">)</span> lat1 <span class="token punctuation">:</span><span class="token punctuation">(</span><span class="token keyword">double</span><span class="token punctuation">)</span> lat2 <span class="token punctuation">:</span><span class="token punctuation">(</span><span class="token keyword">double</span><span class="token punctuation">)</span> lng1 <span class="token punctuation">:</span><span class="token punctuation">(</span><span class="token keyword">double</span><span class="token punctuation">)</span> lng2<span class="token punctuation">{</span>
    
    CLLocation <span class="token operator">*</span>curLocation <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>CLLocation alloc<span class="token punctuation">]</span> initWithLatitude<span class="token punctuation">:</span>lat1 longitude<span class="token punctuation">:</span>lng1<span class="token punctuation">]</span><span class="token punctuation">;</span>
    CLLocation <span class="token operator">*</span>otherLocation <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>CLLocation alloc<span class="token punctuation">]</span> initWithLatitude<span class="token punctuation">:</span>lat2 longitude<span class="token punctuation">:</span>lng2<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">double</span>  distance  <span class="token operator">=</span> <span class="token punctuation">[</span>curLocation distanceFromLocation<span class="token punctuation">:</span>otherLocation<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span>  distance<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>这里计算时间间隔和两个坐标点之间的距离，是为了过滤一些其他不必要的点，iOS采集坐标点跟安卓不一致，是在位置更新之后，会频繁的给出很多坐标点，并没有什么规律，这样还可以优化坐标点飘点的问题，因为高德在iOS上采用的是混合定位，采集方式不可修改，所以只能通过其他的方式去做筛选。尽可能的将异常的点排除掉。  </p>
<h5 id="在地图上添加自定义的大头针，以及标注图"><a href="#在地图上添加自定义的大头针，以及标注图" class="headerlink" title="在地图上添加自定义的大头针，以及标注图"></a>在地图上添加自定义的大头针，以及标注图</h5><pre class=" language-objectivec"><code class="language-objectivec"><span class="token comment" spellcheck="true">/// 自定义用户位置样式</span>
<span class="token operator">-</span> <span class="token punctuation">(</span>MAAnnotationView <span class="token operator">*</span><span class="token punctuation">)</span>mapView<span class="token punctuation">:</span><span class="token punctuation">(</span>MAMapView <span class="token operator">*</span><span class="token punctuation">)</span>mapView viewForAnnotation<span class="token punctuation">:</span><span class="token punctuation">(</span>id<span class="token operator">&lt;</span>MAAnnotation<span class="token operator">></span><span class="token punctuation">)</span>annotation <span class="token punctuation">{</span>
    
    <span class="token comment" spellcheck="true">/* 自定义userLocation对应的annotationView. */</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">[</span>annotation isKindOfClass<span class="token punctuation">:</span><span class="token punctuation">[</span>MAUserLocation class<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">static</span> NSString <span class="token operator">*</span>userLocationStyleReuseIndetifier <span class="token operator">=</span> <span class="token string">@"userLocationStyleReuseIndetifier"</span><span class="token punctuation">;</span>
        MAAnnotationView <span class="token operator">*</span>annotationView <span class="token operator">=</span> <span class="token punctuation">[</span>mapView dequeueReusableAnnotationViewWithIdentifier<span class="token punctuation">:</span>userLocationStyleReuseIndetifier<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>annotationView <span class="token operator">==</span> nil<span class="token punctuation">)</span><span class="token punctuation">{</span>
            annotationView <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>LocationAnnotationView alloc<span class="token punctuation">]</span> initWithAnnotation<span class="token punctuation">:</span>annotation
                                                                reuseIdentifier<span class="token punctuation">:</span>userLocationStyleReuseIndetifier<span class="token punctuation">]</span><span class="token punctuation">;</span>
            annotationView<span class="token punctuation">.</span>canShowCallout <span class="token operator">=</span> YES<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        _locationAnnotationView <span class="token operator">=</span> <span class="token punctuation">(</span>LocationAnnotationView <span class="token operator">*</span><span class="token punctuation">)</span>annotationView<span class="token punctuation">;</span>
        <span class="token punctuation">[</span>_locationAnnotationView updateImage<span class="token punctuation">:</span><span class="token punctuation">[</span>UIImage imageNamed<span class="token punctuation">:</span><span class="token string">@"userPosition"</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> annotationView<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">[</span>annotation isKindOfClass<span class="token punctuation">:</span><span class="token punctuation">[</span>MAPointAnnotation class<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">static</span> NSString <span class="token operator">*</span>customReuseIndetifier <span class="token operator">=</span> <span class="token string">@"customReuseIndetifier"</span><span class="token punctuation">;</span>
        FYCustomAnnotationView <span class="token operator">*</span>annotationView <span class="token operator">=</span> <span class="token punctuation">(</span>FYCustomAnnotationView<span class="token operator">*</span><span class="token punctuation">)</span><span class="token punctuation">[</span>mapView dequeueReusableAnnotationViewWithIdentifier<span class="token punctuation">:</span>customReuseIndetifier<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>annotationView <span class="token operator">==</span> nil<span class="token punctuation">)</span><span class="token punctuation">{</span>
            annotationView <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>FYCustomAnnotationView alloc<span class="token punctuation">]</span> initWithAnnotation<span class="token punctuation">:</span>annotation reuseIdentifier<span class="token punctuation">:</span>customReuseIndetifier<span class="token punctuation">]</span><span class="token punctuation">;</span>
            annotationView<span class="token punctuation">.</span>canShowCallout <span class="token operator">=</span> NO<span class="token punctuation">;</span>
            annotationView<span class="token punctuation">.</span>draggable <span class="token operator">=</span> YES<span class="token punctuation">;</span>
            annotationView<span class="token punctuation">.</span>calloutOffset <span class="token operator">=</span> <span class="token function">CGPointMake</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        __weak <span class="token keyword">typeof</span><span class="token punctuation">(</span>annotationView<span class="token punctuation">)</span> weakAnnotationView <span class="token operator">=</span> annotationView<span class="token punctuation">;</span>
        annotationView<span class="token punctuation">.</span>clickImage <span class="token operator">=</span> <span class="token operator">^</span><span class="token punctuation">{</span>
        
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
        annotationView<span class="token punctuation">.</span>delegate <span class="token operator">=</span> <span class="token keyword">self</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>annotation <span class="token operator">==</span> <span class="token keyword">self</span><span class="token punctuation">.</span>startAnnotation<span class="token operator">||</span>annotation <span class="token operator">==</span> <span class="token keyword">self</span><span class="token punctuation">.</span>trackStartAnnotation<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            annotationView<span class="token punctuation">.</span>image <span class="token operator">=</span> <span class="token punctuation">[</span>UIImage imageNamed<span class="token punctuation">:</span><span class="token string">@"qi"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>annotation <span class="token operator">==</span> <span class="token keyword">self</span><span class="token punctuation">.</span>trackEndAnnotation<span class="token punctuation">)</span><span class="token punctuation">{</span>
            annotationView<span class="token punctuation">.</span>image <span class="token operator">=</span> <span class="token punctuation">[</span>UIImage imageNamed<span class="token punctuation">:</span><span class="token string">@"zhong"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
            annotationView<span class="token punctuation">.</span>image <span class="token operator">=</span> <span class="token punctuation">[</span>UIImage imageNamed<span class="token punctuation">:</span><span class="token string">@"paizhaodian"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> annotationView<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> nil<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>在设置自定义的标注图的时候首先要继承MAAnnotationView<br>在.h文件中  </p>
<pre class=" language-objectivec"><code class="language-objectivec"><span class="token macro property">#<span class="token directive keyword">import</span> &lt;MAMapKit/MAMapKit.h></span>
<span class="token macro property">#<span class="token directive keyword">import</span> "FYCustomCalloutView.h"</span>

NS_ASSUME_NONNULL_BEGIN

<span class="token keyword">@class</span> FYCustomAnnotationView<span class="token punctuation">;</span>

<span class="token keyword">@protocol</span> FYCustomAnnotationViewDelegate <span class="token operator">&lt;</span>NSObject<span class="token operator">></span>

<span class="token operator">-</span> <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>didClickDeleteAnnotationViewWith<span class="token punctuation">:</span><span class="token punctuation">(</span>FYCustomAnnotationView<span class="token operator">*</span><span class="token punctuation">)</span>annotationView<span class="token punctuation">;</span>

<span class="token keyword">@end</span>

<span class="token keyword">@interface</span> FYCustomAnnotationView <span class="token punctuation">:</span> MAAnnotationView


<span class="token keyword">@property</span> <span class="token punctuation">(</span>nonatomic<span class="token punctuation">,</span> strong<span class="token punctuation">)</span> FYCustomCalloutView <span class="token operator">*</span>calloutView<span class="token punctuation">;</span>
<span class="token keyword">@property</span> <span class="token punctuation">(</span>nonatomic<span class="token punctuation">,</span> copy<span class="token punctuation">)</span> <span class="token keyword">void</span><span class="token punctuation">(</span><span class="token operator">^</span>clickImage<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">@property</span> <span class="token punctuation">(</span>nonatomic<span class="token punctuation">,</span> copy<span class="token punctuation">)</span> <span class="token keyword">void</span><span class="token punctuation">(</span><span class="token operator">^</span>clickDeleteImageAction<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">@property</span> <span class="token punctuation">(</span>nonatomic<span class="token punctuation">,</span> weak<span class="token punctuation">)</span> id<span class="token operator">&lt;</span>FYCustomAnnotationViewDelegate<span class="token operator">></span>delegate<span class="token punctuation">;</span>


<span class="token keyword">@end</span>

NS_ASSUME_NONNULL_END
</code></pre>
<p>在.m文件中  </p>
<pre class=" language-objectivec"><code class="language-objectivec"><span class="token macro property">#<span class="token directive keyword">import</span> "FYCustomAnnotationView.h"</span>

<span class="token keyword">@implementation</span> FYCustomAnnotationView

<span class="token operator">-</span> <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>setSelected<span class="token punctuation">:</span><span class="token punctuation">(</span>BOOL<span class="token punctuation">)</span>selected animated<span class="token punctuation">:</span><span class="token punctuation">(</span>BOOL<span class="token punctuation">)</span>animated<span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>selected <span class="token operator">==</span> selected<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>selected<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView <span class="token operator">==</span> nil<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView <span class="token operator">=</span> <span class="token punctuation">[</span>FYCustomCalloutView viewFromXib<span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>alpha <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>frame <span class="token operator">=</span> <span class="token function">CGRectMake</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">105</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>center <span class="token operator">=</span> <span class="token function">CGPointMake</span><span class="token punctuation">(</span><span class="token function">CGRectGetWidth</span><span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>bounds<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">.</span>f <span class="token operator">+</span> <span class="token keyword">self</span><span class="token punctuation">.</span>calloutOffset<span class="token punctuation">.</span>x<span class="token punctuation">,</span> <span class="token operator">-</span><span class="token function">CGRectGetHeight</span><span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>bounds<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">.</span>f <span class="token operator">+</span> <span class="token keyword">self</span><span class="token punctuation">.</span>calloutOffset<span class="token punctuation">.</span>y<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>userInteractionEnabled <span class="token operator">=</span> YES<span class="token punctuation">;</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>photoImgView<span class="token punctuation">.</span>userInteractionEnabled <span class="token operator">=</span> YES<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span> addSubview<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">[</span>UIView animateWithDuration<span class="token punctuation">:</span><span class="token number">0.3</span> animations<span class="token punctuation">:</span><span class="token operator">^</span><span class="token punctuation">{</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>alpha <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
        <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView removeFromSuperview<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">[</span><span class="token keyword">super</span> setSelected<span class="token punctuation">:</span>selected animated<span class="token punctuation">:</span>animated<span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">/**
 重写这个方法，可以让整个在父控件之外的气泡点击也有反应；
 */</span>
<span class="token operator">-</span> <span class="token punctuation">(</span>UIView <span class="token operator">*</span><span class="token punctuation">)</span>hitTest<span class="token punctuation">:</span><span class="token punctuation">(</span>CGPoint<span class="token punctuation">)</span>point withEvent<span class="token punctuation">:</span><span class="token punctuation">(</span>UIEvent <span class="token operator">*</span><span class="token punctuation">)</span>event <span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">// 如果一个子视图的区域超出父视图的bounds，那么正常情况下对子视图在父视图之外区域的触摸操作是不会被识别的，因为父视图的pointInside:withEvent:方法会返回NO，这样的话就不会继续向下遍历子视图了；</span>
    <span class="token comment" spellcheck="true">// 返回一个view来响应事件</span>
    CGPoint point0 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span> convertPoint<span class="token punctuation">:</span>point toView<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>deleteButton<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>deleteButton pointInside<span class="token punctuation">:</span>point0 withEvent<span class="token punctuation">:</span>event<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>delegate <span class="token operator">&amp;&amp;</span> <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>delegate respondsToSelector<span class="token punctuation">:</span><span class="token keyword">@selector</span><span class="token punctuation">(</span>didClickDeleteAnnotationViewWith<span class="token punctuation">:</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>delegate didClickDeleteAnnotationViewWith<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">.</span>deleteButton<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    CGPoint newPoint <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token keyword">self</span> convertPoint<span class="token punctuation">:</span>point toView<span class="token punctuation">:</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>calloutView pointInside<span class="token punctuation">:</span>newPoint withEvent<span class="token punctuation">:</span>event<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">self</span><span class="token punctuation">.</span>clickImage<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">self</span><span class="token punctuation">.</span><span class="token function">clickImage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> <span class="token keyword">self</span><span class="token punctuation">.</span>calloutView<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token keyword">super</span> hitTest<span class="token punctuation">:</span>point withEvent<span class="token punctuation">:</span>event<span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">@end</span>
</code></pre>
<p>标注图calloutView<br>.h文件中  </p>
<pre class=" language-objectivec"><code class="language-objectivec"><span class="token keyword">@interface</span> FYCustomCalloutView <span class="token punctuation">:</span> UIView

<span class="token keyword">@property</span> <span class="token punctuation">(</span>weak<span class="token punctuation">,</span> nonatomic<span class="token punctuation">)</span> IBOutlet UIImageView <span class="token operator">*</span>photoImgView<span class="token punctuation">;</span>
<span class="token keyword">@property</span> <span class="token punctuation">(</span>weak<span class="token punctuation">,</span> nonatomic<span class="token punctuation">)</span> IBOutlet UIButton <span class="token operator">*</span>deleteButton<span class="token punctuation">;</span>

<span class="token keyword">@end</span>
</code></pre>
<p>.m文件中不需要做其他的设置，然后添加坐标点就可以了  </p>
<pre class=" language-objectivec"><code class="language-objectivec"><span class="token comment" spellcheck="true">// 初始化地图上的照片</span>
MAPointAnnotation <span class="token operator">*</span>pointAnnotation <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MAPointAnnotation alloc<span class="token punctuation">]</span> init<span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// 创建位置数据</span>
CLLocationCoordinate2D coordinate <span class="token operator">=</span> <span class="token function">CLLocationCoordinate2DMake</span><span class="token punctuation">(</span><span class="token punctuation">[</span>imageModel<span class="token punctuation">[</span><span class="token string">@"startLatitude"</span><span class="token punctuation">]</span> floatValue<span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token punctuation">[</span>imageModel<span class="token punctuation">[</span><span class="token string">@"startLongitude"</span><span class="token punctuation">]</span> floatValue<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
pointAnnotation<span class="token punctuation">.</span>coordinate <span class="token operator">=</span> coordinate<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// 添加到地图上</span>
<span class="token punctuation">[</span><span class="token keyword">self</span><span class="token punctuation">.</span>mapView addAnnotation<span class="token punctuation">:</span>pointAnnotation<span class="token punctuation">]</span><span class="token punctuation">;</span>
</code></pre>
<p>这样就可以添加了，另外添加起点和终点也是同样</p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/PTLBlog/about" rel="external nofollow noreferrer">小小学生</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://gitee.com/jackPTL/PTLBlog/PTLBlog/2020/01/07/iosbasex4/">https://gitee.com/jackPTL/PTLBlog/PTLBlog/2020/01/07/iosbasex4/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/PTLBlog/about" target="_blank">小小学生</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/PTLBlog/tags/iOS%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/">
                                    <span class="chip bg-color">iOS基础知识总结</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/PTLBlog/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="qq,wechat" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/PTLBlog/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/PTLBlog/medias/reward/alipay1.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/PTLBlog/medias/reward/wechat1.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/PTLBlog/medias/comment_bg.png") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/PTLBlog/libs/valine/av-min.js"></script>
<script src="/PTLBlog/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: '65AHe1vPeY9CGEaXMxn7ilIL-gzGzoHsz',
        appKey: '72O2LjQUWE4kPpH6WhC3QJhk',
        serverURLs: 'https://65ahe1vp.lc-cn-n1-shared.com',
        notify: 'false' === 'true',
        verify: 'false' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: '快来写下你的评论吧'
    });
</script>

<!--酷Q推送-->


    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/PTLBlog/2020/05/09/iosbase5/">
                    <div class="card-image">
                        
                        
                        <img src="/PTLBlog/medias/featureimages/1.jpg" class="responsive-img" alt="关于UIimage存储以及显示的问题">
                        
                        <span class="card-title">关于UIimage存储以及显示的问题</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-05-09
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/PTLBlog/categories/iOS%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/" class="post-category">
                                    iOS基础知识总结
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/PTLBlog/tags/iOS%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E6%80%BB%E7%BB%93/">
                        <span class="chip bg-color">iOS基础知识总结</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/PTLBlog/2019/11/26/macbase1/">
                    <div class="card-image">
                        
                        
                        <img src="/PTLBlog/medias/featureimages/1.jpg" class="responsive-img" alt="提高Xcode编译速度">
                        
                        <span class="card-title">提高Xcode编译速度</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2019-11-26
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/PTLBlog/categories/Mac%E4%BD%BF%E7%94%A8/" class="post-category">
                                    Mac使用
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/PTLBlog/tags/Mac%E4%BD%BF%E7%94%A8/">
                        <span class="chip bg-color">Mac使用</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/PTLBlog/libs/codeBlock/codeBlockFuction.js"></script>



<!-- 代码语言 -->


<!-- 代码块复制 -->

<script type="text/javascript" src="/PTLBlog/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/PTLBlog/libs/codeBlock/codeShrink.js"></script>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/PTLBlog/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    

    <div class="container row center-align"
         style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2024</span>
            
            <!-- <a href="/PTLBlog/about" target="_blank">小小学生</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br> -->
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">11.3k</span>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
                <span id="sitetime"> Loading ...</span>
                <script>
                    var calcSiteTime = function () {
                        var seconds = 1000;
                        var minutes = seconds * 60;
                        var hours = minutes * 60;
                        var days = hours * 24;
                        var years = days * 365;
                        var today = new Date();
                        var startYear = "2019";
                        var startMonth = "6";
                        var startDate = "28";
                        var startHour = "0";
                        var startMinute = "0";
                        var startSecond = "0";
                        var todayYear = today.getFullYear();
                        var todayMonth = today.getMonth() + 1;
                        var todayDate = today.getDate();
                        var todayHour = today.getHours();
                        var todayMinute = today.getMinutes();
                        var todaySecond = today.getSeconds();
                        var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                        var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                        var diff = t2 - t1;
                        var diffYears = Math.floor(diff / years);
                        var diffDays = Math.floor((diff / days) - diffYears * 365);

                        // 区分是否有年份.
                        var language = 'zh-CN';
                        if (startYear === String(todayYear)) {
                            document.getElementById("year").innerHTML = todayYear;
                            var daysTip = 'This site has been running for ' + diffDays + ' days';
                            if (language === 'zh-CN') {
                                daysTip = '本站已运行 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                daysTip = '本站已運行 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = daysTip;
                        } else {
                            document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                            var yearsAndDaysTip = 'This site has been running for ' + diffYears + ' years and '
                                + diffDays + ' days';
                            if (language === 'zh-CN') {
                                yearsAndDaysTip = '本站已运行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                yearsAndDaysTip = '本站已運行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = yearsAndDaysTip;
                        }
                    }

                    calcSiteTime();
                </script>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://jackptl.gitee.io/ptlblog/" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:825473280@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=825473280" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 825473280" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/PTLBlog/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/PTLBlog/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/PTLBlog/libs/materialize/materialize.min.js"></script>
    <script src="/PTLBlog/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/PTLBlog/libs/aos/aos.js"></script>
    <script src="/PTLBlog/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/PTLBlog/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/PTLBlog/js/matery.js"></script>

    

    

    <!-- 雪花特效 -->
     
        <script type="text/javascript">
            // 只在桌面版网页启用特效
            var windowWidth = $(window).width();
            if (windowWidth > 768) {
                document.write('<script type="text/javascript" src="/PTLBlog/libs/others/snow.js"><\/script>');
            }
        </script>
    

    <!-- 鼠标星星特效 -->
    

     
        <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
        <script src="/PTLBlog/libs/others/TencentCaptcha.js"></script>
        <button id="TencentCaptcha" data-appid="xxxxxxxxxx" data-cbfn="callback" type="button" hidden></button>
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/PTLBlog/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/PTLBlog/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    
    <script type="text/javascript" src="/PTLBlog/libs/background/ribbon-dynamic.js" async="async"></script>
    

    
    <script src="/PTLBlog/libs/instantpage/instantpage.js" type="module"></script>
    

<script src="/PTLBlog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/PTLBlog/live2dw/assets/tororo.model.json"},"display":{"position":"left","width":200,"height":250},"mobile":{"show":true},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>

</html>
